/**
 * Created by chenweicheng on 21/6/18.
 */

import {
    Platform,
    StyleSheet,
    processColor
} from 'react-native';
const purple = processColor('#8A2BEA')
const green = processColor('#00ff00');
const yellow = processColor('#ffff00');
const red = processColor('#ee7733');
export  default {
    xAxisA: {
        textColor: processColor('rgb(240,240,240)'),
        textSize: 16,
        gridColor: processColor('red'),
        gridLineWidth: 1,
        axisLineColor: processColor('darkgray'),
        axisLineWidth: 1.5,
        gridDashedLine: {
            lineLength: 10,
            spaceLength: 10
        },
        drawGridLines: false,
        avoidFirstLastClipping: true,
        position: 'BOTTOM',
    },
    yAxisA: {
        left: {
            drawGridLines: false,
            enabled: true
        },
        right: {
            enabled: false,
            drawGridLines: false
        }
    },

    getCustomxAxis(list){

        return {
            textColor: processColor('rgb(240,240,240)'),
            textSize: 16,
            gridColor: processColor('red'),
            gridLineWidth: 1,
            axisLineColor: processColor('darkgray'),
            axisLineWidth: 1.5,
            gridDashedLine: {
                lineLength: 10,
                spaceLength: 10
            },
            drawGridLines: false,
            position: 'BOTTOM',
            valueFormatter: list
        }

    },
    getData(list, n, ifbyCount){
        return {
            dataSets: [{
                values: ifbyCount ? this.getDestCount(eval('(' + JSON.stringify(list) + ')'), n) : this.getPointByArea(eval('(' + JSON.stringify(list) + ')'), n),
                label: '',
                config: {
                    lineWidth: 1.5,
                    drawCircles: false,
                    drawCubicIntensity: 0.3,
                    drawCubic: true,
                    drawHighlightIndicators: false,
                    color: purple,
                    drawFilled: true,
                    fillColor: purple,
                    fillAlpha: 90,
                    mode: "CUBIC_BEZIER",
                    drawValues: false,


                }
            }],
        }
    },
    getDataLine(list, n, ifbyCount){
        return {
            dataSets: [{
                values: this.format01List(ifbyCount ? this.getDestCount(eval('(' + JSON.stringify(list) + ')'), n) : this.getPointByArea(eval('(' + JSON.stringify(list) + ')'), n)),
                label: '',
                config: {
                    lineWidth: 1.5,
                    drawCircles: false,
                    drawCubicIntensity: 0.3,
                    drawCubic: true,
                    drawHighlightIndicators: false,
                    color: purple,
                    drawFilled: false,
                    fillColor: purple,
                    fillAlpha: 90,
                    drawValues: false,


                }
            }],
        }
    },
    getDataThree(list1, list2, list3, n, ifbyCount){
        return {
            dataSets: [{
                values: ifbyCount ? this.getDestCount(eval('(' + JSON.stringify(list1) + ')'), n) : this.getPointByArea(eval('(' + JSON.stringify(list1) + ')'), n),
                label: '',
                config: {
                    lineWidth: 1.5,
                    drawCircles: false,
                    drawCubicIntensity: 0.3,
                    drawCubic: true,
                    drawHighlightIndicators: false,
                    color: yellow,
                    drawFilled: false,
                    fillColor: yellow,
                    fillAlpha: 90,
                    mode: "CUBIC_BEZIER",
                    drawValues: false,


                }
            }, {
                values: ifbyCount ? this.getDestCount(eval('(' + JSON.stringify(list2) + ')'), n) : this.getPointByArea(eval('(' + JSON.stringify(list2) + ')'), n),
                label: '',
                config: {
                    lineWidth: 1.5,
                    drawCircles: false,
                    drawCubicIntensity: 0.3,
                    drawCubic: true,
                    drawHighlightIndicators: false,
                    color: red,
                    drawFilled: false,
                    fillColor: red,
                    fillAlpha: 90,
                    mode: "CUBIC_BEZIER",
                    drawValues: false,
                    axisDependency: "left",


                }
            }, {
                values: ifbyCount ? this.getDestCount(eval('(' + JSON.stringify(list3) + ')'), n) : this.getPointByArea(eval('(' + JSON.stringify(list3) + ')'), n),
                label: '',
                config: {
                    lineWidth: 1.5,
                    drawCircles: false,
                    drawCubicIntensity: 0.3,
                    drawCubic: true,
                    drawHighlightIndicators: false,
                    color: green,
                    drawFilled: false,
                    fillColor: green,
                    fillAlpha: 90,
                    mode: "CUBIC_BEZIER",
                    drawValues: false,

                    axisDependency: "right",
                }
            }
            ],
        }
    },
    format01List(list) {
        let newlist = [];
        //  console.log("format01List", list)
        //console.log("size", list.length)
        for (let i = 0; i < list.length - 1; i++) {
            //  console.log(list[i])
            newlist.push({x: i, y: list[i]})
            if (list[i] != list[i + 1]) {

                newlist.push({x: i + 1, y: list[i]})
            }

        }
        //console.log("before return format01", newlist)
        return newlist
    },
    getPointByArea(list, no) {

        let len = list.length
        //   console.log("list len", len)
        if (len <= no) {
            return list
        }

        let newlist = [];

        let n = parseInt(len * 1.0 / no)

        for (let i = 0; i < n; i++) {
            newlist.push(list[i * no])
        }
        // console.log("size", newlist.length)
        return newlist
    },
    getDestCount(list, count){
        let len = list.length

        //  console.log("list len", len)
        if (len <= count) {
            return list
        }
        let newlist = [];

        let n = parseInt(len * 1.0 / count);

        for (let i = 0; i < count; i++) {
            newlist.push(list[i * n])
        }
        //   console.log("size", newlist.length)
        return newlist
    }
}